package com.nuoniu.sibanyun.service.app.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.app.AppInfo;
import com.nuoniu.sibanyun.mapper.app.AppInfoMapper;
import com.nuoniu.sibanyun.service.app.IAppInfoService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 应用包管理 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-08-12
 */
@Service
public class AppInfoServiceImpl extends ServiceImpl<AppInfoMapper, AppInfo> implements IAppInfoService {

    @Override
    public Page<AppInfo> pageList(Page page, AppInfo appInfo) {
        QueryWrapper wrapper = new QueryWrapper();
        if(appInfo.getType() != null) {
            wrapper.eq("type", appInfo.getType());
        }

        return page(page, wrapper);
    }

    @Override
    public void saveApp(AppInfo appInfo) {
        this.saveOrUpdate(appInfo);
    }

    @Override
    public AppInfo getNewestApp(Integer type) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("type", type);
        wrapper.eq("status", 1);
        wrapper.orderByDesc("create_date");
        wrapper.last("LIMIT 1");
        return getOne(wrapper);
    }
}
